package cn.csc.module.product.dal.mysql.spudetail;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.module.product.controller.admin.spudetail.vo.SpuDetailExportReqVO;
import cn.csc.module.product.controller.admin.spudetail.vo.SpuDetailPageReqVO;
import cn.csc.module.product.dal.dataobject.spudetail.SpuDetailDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigInteger;
import java.util.List;

/**
 * 商品详情信息 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface SpuDetailMapper extends BaseMapperX<SpuDetailDO> {

    default PageResult<SpuDetailDO> selectPage(SpuDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SpuDetailDO>()
                .eqIfPresent(SpuDetailDO::getDetail, reqVO.getDetail())
                .betweenIfPresent(SpuDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SpuDetailDO::getDetailNum));
    }

    default List<SpuDetailDO> selectList(SpuDetailExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SpuDetailDO>()
                .eqIfPresent(SpuDetailDO::getDetail, reqVO.getDetail())
                .betweenIfPresent(SpuDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SpuDetailDO::getDetailNum));
    }

    default List<SpuDetailDO> getHot(){
        return selectList(new LambdaQueryWrapperX<SpuDetailDO>()
                .orderByDesc(SpuDetailDO::getDetailNum)
                .last("limit 10")
        );
    }

    List<SpuDetailDO> selectListDetailNum();

    void updateSpuLookNum(@Param("id") BigInteger id);

}
